$(".select-box ul").on('click','li',function(){
    $(this).parent().siblings('.show').val($(this).html());
    $(this).parent().siblings('.hidden').val($(this).attr('data-id'));
});

$(".select-box div.fl").click(function(e){
    e.stopPropagation();
    var div=$(this);
    div.children('ul').toggleClass('hide');
    var ul=$(this).children('ul');
    $.ajax({
    	type:'GET',
        url:'/DistributorSystem/product/listCustomers',
    	success:function(data){
    		var html="";
    		var customerList=JSON.parse(data).distributorCustomer;
    		for(var i=0;i<customerList.length;i++){
    			html+="<li data-id="+customerList[i].id+">"+customerList[i].name+"</li>";
    		}
    		$(ul).html(html);
    	},
    	error:function(){
    		
    	}
	});
    $(document).click(function() {
        if (!div.children('ul').hasClass("hide")) {
            div.children('ul').addClass("hide");
        }
    });
});



//w调用日期选择插件
$('#datePicker').daterangepicker();
//单选
$(".status").on("click",function(){
    $(this).addClass("on").siblings().removeClass("on");
});

$(document).ready(function(){
	var myChart1 = echarts.init(document.getElementById('chart-block'));
	option = {
	        tooltip: {
	            trigger: 'axis',
	            axisPointer: {
	                type: 'line'
	            }
	        },
	        color:["#E82793","#00ABEE",'#38B035','#F5C53B'],
	        toolbox: {
	            feature: {
	                dataView: {show: false, readOnly: false},
	                magicType: {show: false, type: ['line', 'line','line','line']},
	                restore: {show: false},
	                saveAsImage: {show:false}
	            }
	        },
	        legend: {
	            data:['线下转账','支付宝','微信','挂账']
	        },
	        xAxis: [
	            {
	                type: 'category',
	                data: [],
	                axisLabel: {
	                    interval:0,//横轴信息全部显示,
	                    rotate: 30//30度角倾斜显示
	                }
	            }
	        ],
	        yAxis: [
	            {
	                type: 'value',
	                name: '金额',
	                min: 'dataMin',
	                max: 'dataMax',
	                axisLabel: {
	                    formatter: '￥{value}'
	                },
	                axisLine:{
	                    show:false
	                }
	            }
	        ],
	        series: [
	            {
	                name:'线下转账',
	                type:'line',
	                barWidth:'5px',
	                data:[],
//	                data:xiaxian
	            },
	            {
	                name:'支付宝',
	                type:'line',
	                data:[],
//	                data:zhifubao
	            },
	            {
	                name:'微信',
	                type:'line',
	                data:[],
//	                data:weixin
	            },
	            {
	                name:'挂账',
	                type:'line',
	                data:[],
//	                data:guazhang
	            }
	        ]
	    };
	$.ajax({
		type:'get',
		dataType: "json",
		url:'/DistributorSystem/report/findFundsCounts',
		success:function(data){
			var list=data.fundsCountDtos;
			var dateList=[];
			var gamounts=[];
			var xamounts=[];
			var wamounts=[];
			var zamounts=[];
			for(var i=0;i<list.length;i++){
				var date=list[i].time;
				var newDate=new Date(date).toLocaleString()
				option.xAxis[0].data.push(newDate);
				gamounts.push(list[i].gamount);
				xamounts.push(list[i].xamount);
				wamounts.push(list[i].wamount);
				zamounts.push(list[i].zamount);
			}
			option.series[1].data = gamounts;
			option.series[0].data = xamounts;
			option.series[2].data = wamounts;
			option.series[3].data = zamounts;
			myChart1.setOption(option); 
		},
		error:function(){
			myChart1.showLoading({text: '正在努力的读取数据中...'  });
		}
	})
});
Date.prototype.toLocaleString = function() {
    return (this.getMonth() + 1) + "-" + this.getDate();
};
$('.top-block button').click(function(){
	var myChart1 = echarts.init(document.getElementById('chart-block'));
	var date = $('#datePicker').val();
    arr=date.split(" - "); 
    var startDate = arr[0];
    var endDate = arr[1];
   $("#startdate").val(startDate);
   $("#enddate").val(endDate);
   var id=$('.select-box input.hidden').val();
   $.ajax({
		type:'get',
		dataType: "json",
		url:'/DistributorSystem/report/findFundsCounts?customerId='+id+"&start="+startDate+"&end="+endDate,
		success:function(data){
			var list=data.fundsCountDtos;
			var dateList=[];
			var gamounts=[];
			var xamounts=[];
			var wamounts=[];
			var zamounts=[];
			var html="";
			for(var i=0;i<list.length;i++){
				var date=list[i].time;
				var newDate=new Date(date).toLocaleString()
				option.xAxis[0].data.push(newDate);
				gamounts.push(list[i].gamount);
				xamounts.push(list[i].xamount);
				wamounts.push(list[i].wamount);
				zamounts.push(list[i].zamount);
			}
			option.series[1].data = gamounts;
			option.series[0].data = xamounts;
			option.series[2].data = wamounts;
			option.series[3].data = zamounts;
			myChart1.setOption(option); 
			html+='<tbody><tr><td></td><td></td></tr></tbody>';
		},
		error:function(){
			myChart1.showLoading({text: '正在努力的读取数据中...'  });
		}
	})
})


